#include <QCoreApplication>
#include <thread>

using namespace std;

extern "C" {
#include <libavformat/avformat.h>
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    av_register_all();

    thread t([](){
        const char * filename = "e:/abc.mp4";
        AVFormatContext *oc = avformat_alloc_context();
        avformat_alloc_output_context2(&oc, NULL, "h264", filename);
        AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);
        AVStream *st = avformat_new_stream(oc, codec);
        AVCodecContext *c = st->codec;

        c->codec_id = AV_CODEC_ID_H264;
        c->bit_rate = 400000;
        c->width    = 352;
        c->height   = 288;
        c->time_base.den = 30;
        c->time_base.num = 1;
        c->gop_size      = 12;
        c->pix_fmt       = AV_PIX_FMT_YUV420P;
        if (oc->oformat->flags & AVFMT_GLOBALHEADER)
            c->flags |= CODEC_FLAG_GLOBAL_HEADER;

        int ret = avcodec_open2(c, codec, NULL);
        av_dump_format(oc, 0, filename, 1);

        if (!(oc->oformat->flags & AVFMT_NOFILE)) {
            avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);
        }

        ret = avformat_write_header(oc, NULL);
        av_write_trailer(oc);

        if (!(oc->oformat->flags & AVFMT_NOFILE))
            avio_close(oc->pb);
        avformat_free_context(oc);
    });

    return a.exec();
}
